/**
 * @author liuxin
 * @e-mail lxtobe5@gmail.com
 * @update 2011.12.24
 */
package com.lx.display
{
	import com.lx.display.type.Circle;
	import com.lx.display.type.Ellipse;
	import com.lx.display.type.Rectangle;
	import com.lx.display.type.RoundRectangle;
	import com.lx.display.type.Triangles;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.display.Shader;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Matrix;

	/**
	 * Class contains a set of methods that can use to create a vector shape. Display objects that support
	 * drawing include Sprite and Shape objects. Each of these classes includes a graphics property that is
	 *  a Graphics object. Subclass contains draw() that use to draw kinds of Display objects.
	 */	
	public class Graph
	{
		protected static var $displayObject:*;
		private static var _circle:Circle;
		private static var _ellipse:Ellipse;
		private static var _rectangle:Rectangle;
		private static var _roundRectangle:RoundRectangle;
		private static var _triangles:Triangles;
		
		/**
		 * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. 
		 */		
		public static function clear():void
		{
			$displayObject.graphics.clear();
		}
		
		/**
		 * Specifies a simple one-color fill that subsequent calls to other Graphics methods (such as lineTo()
		 * or drawCircle()) use when drawing. 
		 * @param color  The color of the fill (0xRRGGBB).
		 * @param alpha  The alpha value of the fill (0.0 to 1.0).
		 */		
		public static function fill(color:uint, alpha:Number = 1.0):void
		{
			$displayObject.graphics.beginFill(color,alpha);
		}
		
		/**
		 * Specifies a shader fill used by subsequent calls to other Graphics methods (such as lineTo() or 
		 * drawCircle()) for the object. 
		 * @param shader  The shader to use for the fill. This Shader instance is not required to specify an 
		 *                image input. However, if an image input is specified in the shader, the input must 
		 *                be provided manually. To specify the input, set the input property of the 
		 *                corresponding ShaderInput property of the Shader.data property.
		 * @param matrix  A matrix object (of the flash.geom.Matrix class), which you can use to define 
		 *                transformations on the shader.
		 */		
		public static function fillShader(shader:Shader, matrix:Matrix = null):void
		{
			$displayObject.graphics.beginShaderFill(shader, matrix);
		}
		
		/**
		 * Fills a drawing area with a bitmap image. The bitmap can be repeated or tiled to fill the area. 
		 * @param bitmap  A transparent or opaque bitmap image that contains the bits to be displayed.
		 * @param matrix  A matrix object (of the flash.geom.Matrix class), which you can use to define 
		 *                transformations on the bitmap.
		 * @param repeat  If true, the bitmap image repeats in a tiled pattern. If false, the bitmap image 
		 *                does not repeat, and the edges of the bitmap are used for any fill area that extends 
		 *                beyond the bitmap.
		 * @param smooth  If false, upscaled bitmap images are rendered by using a nearest-neighbor algorithm 
		 *                and look pixelated. If true, upscaled bitmap images are rendered by using a bilinear 
		 *                algorithm. Rendering by using the nearest neighbor algorithm is faster.
		 */		
		public static function fillBitmap(bitmap:BitmapData, matrix:Matrix = null, repeat:Boolean = true, smooth:Boolean = false):void
		{
			$displayObject.graphics.beginBitmapFill(bitmap, matrix, repeat, smooth);
		}
		
		/**
		 * Specifies a gradient fill used by subsequent calls to other Graphics methods (such as lineTo() or 
		 * drawCircle()) for the object. 
		 * @param type                 A value from the GradientType class that specifies which gradient type 
		 *                             to use: GradientType.LINEAR or GradientType.RADIAL.
		 * @param colors               An array of RGB hexadecimal color values used in the gradient; for 
		 *                             example, red is 0xFF0000, blue is 0x0000FF, and so on. You can specify 
		 *                             up to 15 colors. For each color, specify a corresponding value in the 
		 *                             alphas and ratios parameters.
		 * @param alphas               An array of alpha values for the corresponding colors in the colors 
		 *                             array; valid values are 0 to 1. If the value is less than 0, the default
		 *                             is 0. If the value is greater than 1, the default is 1.
		 * @param ratios               An array of color distribution ratios; valid values are 0-255. This 
		 *                             value defines the percentage of the width where the color is sampled at
		 *                             100%. The value 0 represents the left position in the gradient box, and 
		 *                             255 represents the right position in the gradient box.
		 * @param matrix               A transformation matrix as defined by the flash.geom.Matrix class. The 
		 *                             flash.geom.Matrix class includes a createGradientBox() method, which 
		 *                             lets you conveniently set up the matrix for use with the beginGradientFill() 
		 *                             method.
		 * @param spreadMethod         A value from the SpreadMethod class that specifies which spread method 
		 *                             to use, either: SpreadMethod.PAD, SpreadMethod.REFLECT, or SpreadMethod.REPEAT.
		 * @param interpolationMethod  A value from the InterpolationMethod class that specifies which value 
		 *                             to use: InterpolationMethod.LINEAR_RGB or InterpolationMethod.RGB
		 * @param focalPointRatio      A number that controls the location of the focal point of the gradient. 
		 *                             0 means that the focal point is in the center. 1 means that the focal 
		 *                             point is at one border of the gradient circle. -1 means that the focal 
		 *                             point is at the other border of the gradient circle. A value less than 
		 *                             -1 or greater than 1 is rounded to -1 or 1. 
		 */		
		public static function fillGradient(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0):void
		{
			$displayObject.graphics.beginGradientFill(type, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio);
		}
		
		/**
		 * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or
		 * the drawCircle() method. 
		 * @param thickness     An integer that indicates the thickness of the line in points; valid values 
		 *                      are 0-255. If a number is not specified, or if the parameter is undefined, a 
		 *                      line is not drawn. If a value of less than 0 is passed, the default is 0. The 
		 *                      value 0 indicates hairline thickness; the maximum thickness is 255. If a value 
		 *                      greater than 255 is passed, the default is 255.
		 * @param color         A hexadecimal color value of the line; for example, red is 0xFF0000, blue is 
		 *                      0x0000FF, and so on. If a value is not indicated, the default is 0x000000 
		 *                      (black). Optional.
		 * @param alpha         A number that indicates the alpha value of the color of the line; valid values 
		 *                      are 0 to 1. If a value is not indicated, the default is 1 (solid). If the 
		 *                      value is less than 0, the default is 0. If the value is greater than 1, the 
		 *                      default is 1.
		 * @param pixelHinting  (Not supported in Flash Lite 4) A Boolean value that specifies whether to 
		 *                      hint strokes to full pixels. This affects both the position of anchors of a 
		 *                      curve and the line stroke size itself. With pixelHinting set to true, line 
		 *                      widths are adjusted to full pixel widths. With pixelHinting set to false, 
		 *                      disjoints can appear for curves and straight lines. 
		 * @param scaleMode     (Not supported in Flash Lite 4) A value from the LineScaleMode class that 
		 *                      specifies which scale mode to use:
		 * @param caps          (Not supported in Flash Lite 4) A value from the CapsStyle class that 
		 *                      specifies the type of caps at the end of lines. Valid values are: 
		 *                      CapsStyle.NONE, CapsStyle.ROUND, and CapsStyle.SQUARE. If a value is not 
		 *                      indicated, Flash uses round caps.
		 * @param joints        (Not supported in Flash Lite 4) A value from the JointStyle class that 
		 *                      specifies the type of joint appearance used at angles. Valid values are: 
		 *                      JointStyle.BEVEL, JointStyle.MITER, and JointStyle.ROUND. If a value is not 
		 *                      indicated, Flash uses round joints.
		 * @param miterLimit    (Not supported in Flash Lite 4) A number that indicates the limit at which a 
		 *                      miter is cut off. Valid values range from 1 to 255 (and values outside that 
		 *                      range are rounded to 1 or 255). This value is only used if the jointStyle is 
		 *                      set to "miter". The miterLimit value represents the length that a miter can 
		 *                      extend beyond the point at which the lines meet to form a joint. The value 
		 *                      expresses a factor of the line thickness. For example, with a miterLimit 
		 *                      factor of 2.5 and a thickness of 10 pixels, the miter is cut off at 25 pixels.
		 */		
		public static function line(thickness:Number = NaN, color:uint = 0, alpha:Number = 1.0, pixelHinting:Boolean = false, scaleMode:String = "normal", caps:String = null, joints:String = null, miterLimit:Number = 3):void
		{
			$displayObject.graphics.lineStyle(thickness, color, alpha, pixelHinting, scaleMode, caps, joints, miterLimit);
		}
		
		/**
		 * Specifies a bitmap to use for the line stroke when drawing lines. 
		 * @param bitmap  The bitmap to use for the line stroke.
		 * @param matrix  An optional transformation matrix as defined by the flash.geom.Matrix class. The 
		 *                matrix can be used to scale or otherwise manipulate the bitmap before applying it to
		 *                the line style.
		 * @param repeat  Whether to repeat the bitmap in a tiled fashion.
		 * @param smooth  Whether smoothing should be applied to the bitmap.
		 */		
		public static function lineBitmap(bitmap:BitmapData, matrix:Matrix = null, repeat:Boolean = true, smooth:Boolean = false):void
		{
			$displayObject.graphics.lineBitmapStyle(bitmap, matrix, repeat, smooth);
		}
		
		/**
		 * Specifies a shader to use for the line stroke when drawing lines. 
		 * @param shader  The shader to use for the line stroke.
		 * @param matrix  An optional transformation matrix as defined by the flash.geom.Matrix class. The 
		 *                matrix can be used to scale or otherwise manipulate the bitmap before applying it to
		 *                the line style.
		 */		
		public static function lineShader(shader:Shader, matrix:Matrix = null):void
		{
			$displayObject.graphics.lineShaderStyle(shader, matrix);
		}
		
		/**
		 * Specifies a gradient to use for the stroke when drawing lines.
		 * @param type                 A value from the GradientType class that specifies which gradient type 
		 *                             to use, either GradientType.LINEAR or GradientType.RADIAL.
		 * @param colors               An array of RGB hex color values to be used in the gradient.
		 * @param alphas               An array of alpha values for the corresponding colors in the colors 
		 *                             array; valid values are 0 to 1. If the value is less than 0, the 
		 *                             default is 0. If the value is greater than 1, the default is 1.
		 * @param ratios               An array of color distribution ratios; valid values are from 0 to 255. 
		 * @param matrix               A transformation matrix as defined by the flash.geom.Matrix class. 
		 * @param spreadMethod         A value from the SpreadMethod class that specifies which spread method 
		 *                             to use
		 * @param interpolationMethod  A value from the InterpolationMethod class that specifies which value 
		 *                             to use. 
		 * @param focalPointRatio      A number that controls the location of the focal point of the gradient. 
		 */		
		public static function lineGradient(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0):void
		{
			$displayObject.graphics.lineGradientStyle(type, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio);
		}
		
		public static function get getSprite():Sprite
		{
			return $displayObject = new Sprite();
		}
		
		public static function get getMovieClip():MovieClip
		{
			return $displayObject = new MovieClip();
		}
		
		public static function get getShape():Shape
		{
			return $displayObject = new Shape();
		}
		
		public static function get typeCircle():Circle
		{
			if(_circle == null)
			{
				_circle = new Circle();
			}
			return _circle;
		}
		
		public static function get typeEllipse():Ellipse
		{
			if(_ellipse == null)
			{
				_ellipse = new Ellipse();
			}
			return _ellipse;
		}
		
		public static function get typeRectangle():Rectangle
		{
			if(_rectangle == null)
			{
				_rectangle = new Rectangle();
			}
			return _rectangle;
		}
		
		public static function get typeRoundRectangle():RoundRectangle
		{
			if(_roundRectangle == null)
			{
				_roundRectangle = new RoundRectangle();
			}
			return _roundRectangle;
		}
		
		public static function get typeTriangles():Triangles
		{
			if(_triangles == null)
			{
				_triangles = new Triangles();
			}
			return _triangles;
		}
	}
}